<template>

  <a-modal
    centered
    title="选择专家"
    :width="1000"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
      <!-- 查询表单 -->
      <div style="padding: 20px;">
        <a-form :form="searchForm" layout="inline">
          <!-- 查询表单项 -->
          <a-form-item label="姓名">
            <a-input v-model="searchParams.talentRealName" />
          </a-form-item>
          <a-form-item label="手机号">
            <a-input v-model="searchParams.talentAllPhoneNumber" />
          </a-form-item>
          <a-form-item>
            <a-button type="primary" @click="search">查询</a-button>
            <a-button type="primary" ghost @click="reset" style="margin-left: 10px;">重置</a-button>
          </a-form-item>
        </a-form>
      </div>

      <!-- 列表展示 -->
      <a-table :columns="columns" :dataSource="dataSource" :loading="loading" :key="tableKey" :pagination="false"
               :rowSelection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange}">
        <template slot="action" slot-scope="text, record">
          <a-button type="primary" @click="lookFruit(record)">查看成果</a-button>
        </template>
      </a-table>
      <br/>
      <!-- 分页器 -->
      <a-pagination :show-total="total => `共${total}条`" :total="total" :current="pagination.current" :pageSize="pagination.pageSize" @change="handlePaginationChange" />
  </a-modal>
</template>

<script>
import {postAction} from "@/api/esManage";

export default {
  components: {
  },
  data() {
    return {
      visible: false,
      searchForm: null,
      searchParams: {
        talentRealName: "",
        talentAllPhoneNumber: ""
      },
      tableKey: "",
      dataSource: [],
      // 选中的行
      selectedRows: [],
      selectedRowKeys: [],
      columns: [
        {
          title: "序号",
          dataIndex: "key",
          key: "key",
          align: "center",
          customRender: (text,record,index) => `${index+1}`,//此处为重点
        },
        {
          title: '姓名',
          dataIndex: 'talentRealName',
        },
        {
          title: '手机号',
          dataIndex: 'talentAllPhoneNumber',
          key: 'talentAllPhoneNumber',
          ellipsis: true,
        },
        {
          title: '工作单位',
          dataIndex: 'talentCompany',
          key: 'talentCompany',
          ellipsis: true,
        },
        {
          title: '研究领域',
          dataIndex: 'talentFields',
          key: 'talentFields',
          ellipsis: true,
        },
        // {
        //     title: '合作次数',
        //     dataIndex: 'cooperationNum',
        //     key: 'cooperationNum',
        //     width: '10%'
        // },
        // 其他列配置
        // ...
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      imageUrl: "",
      loading: false,
      total: 0,
      pagination: {
        current: 1,
        pageSize: 10
      },
      modalForm: null,
      modal: {
        visible: false,
        title: '',
        record: null,
        formData: {}
      },
      mergeModal: {
        visible: false,
        title: '合并专家',
        record: null,
        formData: {
          mergeSelectedVal: '',
          waitMergeData: []
        }
      },
      mergeLoading: false,
      showFruitModal: false,
      talentId: null,
      importModal: false
    };
  },
  methods: {
    search() {
      this.pagination.current = 1;
      this.selectedRows = [];
      this.selectedRowKeys = [];
      this.fetchData();
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      if(this.selectedRowKeys.length > 1){
        this.$message.error("请选择一条数据")
        return;
      }
      console.log('选中的行:', selectedRows);
    },
    handlePaginationChange(page, pageSize) {
      this.pagination.current = page;
      this.pagination.pageSize = pageSize;
      this.fetchData();
    },
    reset() {
      this.searchParams = {};
      this.pagination = {
        current: 1,
        pageSize: 10
      };
      this.fetchData();
    },
    fetchData() {
      this.dataSource = [];
      this.loading = true;
      let url = "/talents/manage/pageList";
      let that = this;
      let obj = {
        ...this.searchParams,
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize
      }
      this.mergeModal.formData.waitMergeData = []
      this.mergeModal.formData.mergeSelectedVal = '';
      this.tableKey = Math.random();
      postAction(url, obj).then(res => {
        if (res.data.success) {
          that.dataSource = res.data.result.records;
          that.total = parseInt(res.data.result.total);
          this.loading = false;
        }
      }).catch(err => {
        console.log(err)
        this.loading = false;
      })
    },
    handleCancel() {
      this.visible = false;
    },
    handleOk() {
      if(this.selectedRowKeys.length > 1){
        this.$message.error("请选择一条数据")
        return;
      }
      this.dataSource2 = this.selectedRows;
      this.$emit("selectFinished", this.dataSource2);
      this.visible = false;
    },
  },
  created() {
    this.fetchData();
  },
};
</script>

<style scoped>
/* 样式 */
.avatar-uploader > .ant-upload {
  width: 100px;
  height: 100px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
</style>
